package com.raysun.androidbase.interaction.extension

import android.util.Log
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.ActivityResultRegistry
import androidx.activity.result.contract.ActivityResultContracts
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner

class MyLifecycleObserver(private val registry: ActivityResultRegistry) : DefaultLifecycleObserver {

    private lateinit var getContentLauncher: ActivityResultLauncher<String>

    override fun onCreate(owner: LifecycleOwner) {
        getContentLauncher = registry.register("key", owner, ActivityResultContracts.GetContent()) {
            Log.d("Raysunshine", "getContent: $it")
        }
    }

    fun selectImage() {
        getContentLauncher.launch("image/*")
    }
}